<table border="0" width="100%" cellspacing="5" cellpadding="0" align="center">
{% for figure_list in figures_table %}
<tr>
  {% for figure in figure_list %}
  <td align="center">
  <div class="cube-figure-thumb-block">
  <div>
    {{ figure|cube_figure_thumbnail|safe }}
  </div>
  <div><b>{{ figure.name }}</b></div>  
  <div><small>{{ figure.date|date:"d.m.Y H:i" }}</small></div>
  
  <div><small>by {{ figure.author.nickname }}</small></div>
  
  {% if user_info.user|equal:figure.author or user_info.admin %}
    <div>
      <a href="/post/edit?attach_cube_figure={{ figure.key }}">Post</a>
      <a href="/cube/constructor?{{ figure.figure_key_param }}">Edit</a>
      <a href="/cube/figure/delete?{{ figure.figure_key_param }}">Delete</a>
    </div>
  {% else %}    
  {% endif %}
  {% if user_info.admin %}
    <center>
    <div class="rating rating{{ figure.rating|default:0}}" figure_name="{{ figure.url_name }}" rating="{{ figure.rating|default:0}}"></div>
    </center>
  {% else %}    
  {% endif %}
  
  </td>
  {% endfor %}
</tr>
{% endfor %}
</table>

{% if cube_prev_page_url %}
<a href="{{ cube_prev_page_url }}"><img src="/template/prev-page.gif" border="0"></a>
{% endif %}

{% if cube_next_page_url %}
<a href="{{ cube_next_page_url }}"><img src="/template/next-page.gif" border="0"></a>
{% endif %}

{% if user_info.admin %}
<script language="JavaScript">
function showElementRating(elem,rating) {
	for (var i=0; i<11; i++) {
		elem.removeClass("rating"+i);
	}
	elem.addClass("rating"+rating);
}

$(function() {
	$(".rating").each(function() {
		$(this).mousemove(function(event){
			var x=event.clientX-$(this).offset().left;
			var r=Math.floor(x*11/100);
			showElementRating($(this),r);
		})
		
		$(this).mouseout(function(event) {
			var r=$(this).attr("rating");
			showElementRating($(this),r);
		});
		
		$(this).mousedown(function(event) {
			var x=event.clientX-$(this).offset().left;
			var r=Math.floor(x*11/100);
			var name=$(this).attr("figure_name");
			var elem=$(this)
			$.get("/cube/figure/rating?cube_figure="+name+"&rating="+r,
				function(data) {
					elem.attr("rating",data);
					showElementRating(elem,data);
				});
		});
	})
})
</script>
{% endif %}
